//
//  BaseTabBarViewController.m
//  wensheng-sijicaifu
//
//  Created by fuyu on 2017/5/20.
//  Copyright © 2017年 fuyu. All rights reserved.
//

#import "BaseTabBarViewController.h"
#import "MBHomeViewController.h"
#import "NSHomeViewController.h"
#import "KLModelListViewController.h"
#import "MBWLMListViewController.h"
#import "MBMineViewController.h"
#import "NSMineViewController.h"
@interface BaseTabBarViewController ()<UITabBarControllerDelegate>

@property (nonatomic, strong, nullable) NSArray <UIViewController *> *controllerArray;
@property (nonatomic, strong) NSArray *imageArray;
@property (nonatomic, strong) NSArray *selectedimageArray;
@end

@implementation BaseTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    NSArray  *titleArray = [NSArray arrayWithObjects:@"",@"",@"", nil];
    _imageArray = [NSArray arrayWithObjects:@"cloth_normal",@"fashion_normal",@"set_normal", nil];
    _selectedimageArray = [NSArray arrayWithObjects:@"cloth_select",@"fashion_select",@"set_select", nil];
    
    _controllerArray  = [NSArray arrayWithObjects: [[BaseNavViewController alloc] initWithRootViewController:[[MBHomeViewController alloc] init]],[[BaseNavViewController alloc]initWithRootViewController:[[KLModelListViewController alloc]init]],
                         [[BaseNavViewController alloc]initWithRootViewController:[[MBMineViewController alloc]init]],nil];
    
    //debugTest
    if ([MBUserAccount defaultAccount].isUserType) {
        //为了显示wlm角标
        [[MBWhoLikeMeDataManager sharedManager] getWhoLikeMeList:^(BOOL success) {
            if (success && [MBWhoLikeMeDataManager sharedManager].listDataArr.count > 0) {
                [self.tabBar.items[1] setBadgeValue:[NSString stringWithFormat:@"%ld",[MBWhoLikeMeDataManager sharedManager].listDataArr.count]];
            } else {
                [self.tabBar.items[1] setBadgeValue:nil];
            }
        }];
        //
        _imageArray = [NSArray arrayWithObjects:@"tabbar_home_normal",@"tabbar_wlm_normal",@"tabbar_mine_normal", nil];
        _selectedimageArray = [NSArray arrayWithObjects:@"tabbar_home_select",@"tabbar_wlm_select",@"tabbar_mine_select", nil];
        _controllerArray  = [NSArray arrayWithObjects: [[BaseNavViewController alloc] initWithRootViewController:[[NSHomeViewController alloc] init]],[[BaseNavViewController alloc]initWithRootViewController:[[MBWLMListViewController alloc] init]],
                             [[BaseNavViewController alloc]initWithRootViewController:[[NSMineViewController alloc]init]],nil];
    }
    for (int i = 0 ; i < _controllerArray.count; i++) {
        [self  addTabbarItemWithViewControler:_controllerArray[i] Title:titleArray[i] image:_imageArray[i] selectedImage:_selectedimageArray[i]];
    }
//    self.tabBar.backgroundColor = HEXS(@"F0EDFF");
    
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.image = [UIImage imageNamed:@"tabbar_back"];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.frame = CGRectMake(0, 0, ScreenWidth, TabbarHeight);
        [[UITabBar appearance] insertSubview:imageView atIndex:0];
//    imageView.frame = self.tabBar.bounds;
    [UITabBar appearance].translucent = NO;
    self.viewControllers = _controllerArray;
}

- (void)addTabbarItemWithViewControler:(UIViewController *)Vc  Title:(NSString *)title  image:(NSString *)image  selectedImage:(NSString *)selsetedImge{
    UITabBarItem  *item = [[UITabBarItem alloc]init];
//    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : HEXS(@"333333")} forState:UIControlStateSelected];;
//    item.title = title;
    item.image = [[UIImage  imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    item.selectedImage  = [[UIImage  imageNamed:selsetedImge] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    item.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    Vc.tabBarItem  = item;
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    return YES;
}

@end
